import React, { Component } from 'react'
import {Switch,Route,Redirect} from 'react-router-dom'
export default class RouterView extends Component {
    render() {
        let {routes} = this.props
        return (
            <div>
                <Switch>
                    {
                        routes.map((item,index)=>{
                            if(item.from){
                                return <Redirect key={index} exact from={item.from} to={item.to}></Redirect>
                            }
                            if(!item.from && item.to){
                                return <Redirect key={index} to={item.to}></Redirect>
                            }
                            return <Route key={index} path={item.path} render={(router)=>{
                                let Com = item.component
                                return <Com {...router}/>
                            }}></Route>
                        })
                    }
                </Switch>
            </div>
        )
    }
}
